package cn.kgc.crowdfundingadmin03.service;

import cn.kgc.crowdfundingadmin03.mapper.MessageMapper;
import cn.kgc.crowdfundingadmin03.pojo.Message;
import cn.kgc.crowdfundingadmin03.pojo.MessageExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-03-01 16:31
 */
@Service("messageService")
public class MessageServiceImpl implements MessageService {

    @Resource
    MessageMapper messageMapper;

    @Override
    public List<Message> getAll() {
       /* MessageExample example=new MessageExample();
        MessageExample.Criteria criteria = example.createCriteria();*/
        List<Message> messages = messageMapper.selectByExample(null);
        return messages;
    }

    @Override
    public PageInfo<Message> queryForKeywordSearch(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        MessageExample example=new MessageExample();
        MessageExample.Criteria criteria = example.createCriteria();
        criteria.andContentLike("%"+keyword+"%");
        List<Message> advertisements = messageMapper.selectByExample(example);
        PageInfo<Message> pageInfo=new PageInfo<>(advertisements);
        return  pageInfo;
    }

    @Override
    public void updateMessage(Message message) {

         messageMapper.updateByPrimaryKey(message);
    }

    @Override
    public List<Message> getMessageListByIdList(List<Integer> messageIdList) {
        MessageExample example=new MessageExample();
        MessageExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(messageIdList);
        List<Message> messages = messageMapper.selectByExample(example);
        return messages;
    }
}
